import React from 'react';
import { Tabs } from 'antd';
import { useSearchParams } from 'react-router-dom';
import OCRTool from '../components/OCRTool';
import PDFConverter from '../components/PDFConverter';
import styles from './PDFToolPage.module.css';

interface PDFToolPageProps {
  setToolbar: (toolbar: React.ReactNode) => void;
}

const PDFToolPage: React.FC<PDFToolPageProps> = ({ setToolbar }) => {
  const [searchParams] = useSearchParams();
  const defaultTab = searchParams.get('tab') || 'ocr';

  React.useEffect(() => {
    setToolbar(null);
    return () => setToolbar(null);
  }, [setToolbar]);

  const items = [
    {
      key: 'ocr',
      label: 'OCR文字识别',
      children: <OCRTool />
    },
    {
      key: 'convert',
      label: 'PDF转换',
      children: <PDFConverter />
    }
  ];

  return (
    <div className={styles.container}>
      <Tabs 
        items={items} 
        defaultActiveKey={defaultTab}
        onChange={(key) => {
          const newSearchParams = new URLSearchParams(searchParams);
          newSearchParams.set('tab', key);
          window.history.replaceState(null, '', `?${newSearchParams.toString()}`);
        }}
        className={styles.tabs}
      />
    </div>
  );
};

export default PDFToolPage; 